<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<script>
var
/* 事件 */
    Events = {
        exportAction: function () {
            $.post(webRoot+"/system/voucher/exportAction.json", {
                "startperiod": $("#startDate").val(),
                "endperiod": $("#endDate").val()
            }, function (ret) {
                layer.alert(ret.message)
            })
        },
        downloadAction:function(){

            $.post(webRoot+"/system/voucher/downloadBeforeAction.json", {}, function (ret) {
                if(!ret.success){
                    layer.alert(ret.message)
                }else{
                    var url = webRoot+"/system/voucher/downloadAction";

                    var $iframe,
                        iframe_doc,
                        iframe_html;

                    if (($iframe = $('#download_iframe')).length === 0) {
                        $iframe = $("<iframe id='download_iframe'" +
                            " style='display: none' src='about:blank'></iframe>"
                        ).appendTo("body");
                    }

                    iframe_doc = $iframe[0].contentWindow || $iframe[0].contentDocument;
                    if (iframe_doc.document) {
                        iframe_doc = iframe_doc.document;
                    }

                    iframe_html = "<html><head></head><body><form method='POST' action='" +
                        url + "'></form>" +
                        "</body></html>";

                    iframe_doc.open();
                    iframe_doc.write(iframe_html);
                    $(iframe_doc).find('form').submit();
                }
            })
        }

    },
/* 画面对象 */
    Page = {
        // 初始化Validator
        initValidator: function () {

        },

        // 事件初期化
        initEvents: function () {
            //$('.J_menuItem').on('click', top.menuItem);
            $(".fn-export").click(Events.exportAction);
            $(".fn-download").click(Events.downloadAction);

        },

        // 画面初始化
        initialize: function () {
            Common.bindingDateYMStartEnd("startDate", "endDate");
        },

        init: function () {
            Page.initialize();
            Page.initEvents();
            Page.initValidator();
        }
    };

jQuery(document).ready(function () {
    Page.init();
});
</script>
